#include <cassert>

#include "MSize.h"

MSize::MSize( float width, float height ) : _width( width ), _height( height ) 
{

}

MSize::MSize( const MSize& size ) :	_width( size.width() ), _height( size.height() )
{

}

MSize& MSize::operator = ( const MSize& size )
{ 
	_width = size.width();
	_height = size.height();
	return *this;
}

MSize::~MSize()
{
}

void MSize::setWidth( float width )
{
	_width = width;
}

float MSize::width() const
{
	return _width;
}

void MSize::setHeight( float height )
{
	_height = height;
}

float MSize::height() const
{
	return _height;
}

MSize MSize::operator + ( const MSize& size )
{
	return MSize( width() + size.width(), height() + size.height() );
}

MSize& MSize::operator += ( const MSize& size )
{
	setWidth( width() + size.width() );
	setHeight( height() + size.height() );
	return *this;
}

MSize MSize::operator - ( const MSize& size )
{
	return MSize( width() - size.width(), height() - size.height() );
}

MSize MSize::operator * ( const MSize& size )
{
	return MSize( width() * size.width(), height() * size.height() );
}

MSize MSize::operator / ( const MSize& size )
{
	assert( size.width() );
	assert( size.height() );

	MSize result;

	if ( size.width() )
	{
		result.setWidth( width() / size.width() );
	}

	if ( size.height() )
	{
		result.setHeight( height() / size.height() );
	}

	return result;
}

bool MSize::operator > ( const MSize& size )
{
	return ( _width > size.width() || _height > size.height() ) ? true : false;
}

std::ostream& operator << ( std::ostream& stream, const MSize& size )
{
	stream << "MSize width = " << size.width() << ", height = " << size.height() << std::endl;
	return stream;
}

MSize MSize::operator + ( float n )
{
	return MSize( width() + n, height() + n );
}

MSize MSize::operator - ( float n )
{
	return MSize( width() - n, height() - n );
}

MSize MSize::operator * ( float n )
{
	return MSize( width() * n, height() * n );
}

MSize MSize::operator / ( float n )
{
	assert( n );

	MSize result;

	if ( n )
	{
		result.setWidth( width() / n );
		result.setHeight( height() / n );
	}

	return result;
}

bool MSize::operator > ( float n )
{
	return ( _width > n && _height > n ) ? true : false;
}

MSize abs( MSize& size )
{
	return MSize( abs( size.width() ), abs( size.height() ) );
}